package MapDemo;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class MapRongQi {
    public static void main(String[] args) {
        HashMap<String, String> hm = new HashMap<String, String>();
        //添加元素
        System.out.println(hm.put("暴强", "荣荣"));             //null
        System.out.println(hm.put("小强", "大荣"));             //null
        System.out.println(hm.put("大枪", "笑容"));             //null
        System.out.println(hm.put("中枪", "晓容"));             //null
        //删除
        System.out.println(hm.remove("小强"));
        //修改元素
        System.out.println(hm.put("暴强", "小网红"));
        System.out.println("------------------------------");
        System.out.println(hm.containsKey("大枪"));
        System.out.println(hm.containsKey("小强"));
        System.out.println(hm.containsKey("暴强"));
        System.out.println(hm.containsKey("中枪"));
        System.out.println(hm.size());
        System.out.println(hm.size());
        System.out.println("----------------");
        Set<String> keys = hm.keySet();
        //遍历
        for (String key : keys) {
            System.out.println(key);
            System.out.println("----------------------");
            Collection<String> values = hm.values();
            for (String value : values) {
                System.out.println(value);

            }
        }
    }
}
